package Utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName RabbitMq.Utils.ConnectionFactoryUtil
 * @Description TDD
 * @Author 混沌酱
 * @Date 2023-10-09 9:09
 * @Version 1.0
 **/
public class ConnectionFactoryUtil {

    public static Connection getConnection() throws IOException, TimeoutException {

        // 建立工厂连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        // 设置服务地址
        connectionFactory.setHost("localhost");
        // 设置端口
        connectionFactory.setPort(5672);
        // 设置连接登录账号
        connectionFactory.setUsername("root");
        // 设置连接登录密码
        connectionFactory.setPassword("yyf==123");
        // 连接指定虚拟机名称
        connectionFactory.setVirtualHost("test");
        // 建立连接
        Connection connection = connectionFactory.newConnection();

        return connection;
    }
}
